package com.cn.esermis.config;
import com.cn.esermis.utils.TableCreator;
import com.cn.esermis.utils.TableUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

@Component
public class TableInitRunner implements CommandLineRunner {

    private final TableCreator tableCreator;

    @Autowired
    public TableInitRunner(TableCreator tableCreator) {
        this.tableCreator = tableCreator;
    }
    @Resource
    private TableUtils tableUtils;
    public static List<String> existingTables = new ArrayList<>();


    @Override
    public void run(String... args) {
        // 生成当前月份的表后缀（如 202310）
        String currentMonth = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMM"));
        tableCreator.createTableIfAbsent("air_monitor_hour_record", currentMonth);
        tableCreator.createTableIfAbsent("air_monitor_minute_record", currentMonth);
        tableCreator.createTableIfAbsent("water_monitor_hour_record", currentMonth);
        tableCreator.createTableIfAbsent("water_monitor_minute_record", currentMonth);
    }
}